<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          @click="handleUpdate"
          v-hasPermi="['base:config:edit']"
        >修改</el-button>
      </el-col>
    </el-row>
    <el-row style="padding-top: 40px;padding-left: 5%;font-size: 20px">
      <el-tabs tab-position="left" @tab-click="handleClick">
        <el-tab-pane label="客服电话">
          <el-row>
            <el-col :span="15">
              <h3 style="text-align: center">客服电话</h3>
              <h3 style="text-align: center">{{config.phone}}</h3>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="关于鲁客">
          <el-row>
            <el-col :span="18">
              <h3 style="text-align: center">关于鲁客</h3>
              <div class="description editor ">
                <div class="ql-container ql-snow" style="border: none;">
                  <div class="ql-editor">
                    <p v-html="config.about"></p>
                  </div>
                </div>
              </div>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="使用说明"><el-row>
          <el-col :span="18">
            <h3 style="text-align: center">使用说明</h3>
            <div class="description editor ">
              <div class="ql-container ql-snow" style="border: none;">
                <div class="ql-editor">
                  <p v-html="config.instructions"></p>
                </div>
              </div>
            </div>
          </el-col>
        </el-row></el-tab-pane>

      </el-tabs>
    </el-row>

    <!-- 添加或修改配置管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules">
        <el-form-item v-if="index==0"  prop="phone">
          <el-input v-model="form.phone" placeholder="请输入客服电话" />
        </el-form-item>
        <el-form-item v-if="index==1">
          <editor v-model="form.about" :min-height="500"/>
        </el-form-item>
        <el-form-item v-if="index== 2">
          <editor v-model="form.instructions" :min-height="500"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getConfig, updateConfig } from "@/api/base/config";
import Editor from '@/components/Editor';

export default {
  name: "lkConfig",
  components: {
    Editor,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      config:{},
      rules: {},
      index:0

    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClick(tab) {
      this.index=tab.index
    },
    /** 查询配置管理列表 */
    getList() {
      getConfig(1).then(response => {
        this.config=response.data;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 修改按钮操作 */
    handleUpdate() {
        this.open = true;
        if(this.index==0){
          this.title = "修改客服电话";
        }else if(this.index==1){
          this.title = "修改关于鲁客";
        }else if(this.index==2){
          this.title = "修改使用说明";
        }
      getConfig(1).then(response => {
        this.form = response.data;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateConfig(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    }
  }
};
</script>
